<template>
    <div class="store">
        <header>门店管理</header>
        <div class="contents">
            <div class="ad_list">
                <div class="ad_list_title">
                    <el-button type="danger" style="background:#e7251a;" @click.native="addStore">新增门店</el-button>
                </div>
                <div class="ad_list_tab">
                    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
                        <el-tab-pane label="全部" name="2"></el-tab-pane>
                        <el-tab-pane label="营业中" name="1"></el-tab-pane>
                        <el-tab-pane label="关闭" name="0"></el-tab-pane>
                    </el-tabs>
                    <el-input style="width:272px;margin:0 15px 0 20px;" v-model.trim="input1" placeholder="请输入">
                        <el-button slot="append" icon="el-icon-search" @click.native="search"></el-button>
                    </el-input>
                </div>
            </div>
            <div class="selected" v-if="selectArr.length>0">
                <p>
                    <img src="../../assets/images/market/select2.png" alt="" />
                    <span>已选择&nbsp;
                        <label>{{selectArr.length}}</label>&nbsp;项</span>
                </p>
            </div>
            <div class="tables">
                <el-table v-loading="loading" :data="listDatas" style="width: 100%" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="50"> </el-table-column>
                    <el-table-column prop="SHOPNAME" label="门店名称" width="250"> </el-table-column>
                    <el-table-column prop="ADDRESS" label="地址" width="400"> </el-table-column>
                    <el-table-column prop="TOTALAMOUNT" label="月营业额" sortable width="200">
                        <template slot-scope="scope">
                            <span>{{scope.row.TOTALAMOUNT}}万</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="STATUS" label="状态" width="150">
                        <template slot-scope="scope">
                            <span v-if="scope.row.STATUS==1" style="display:flex;align-items:center;justify-content:center;">
                                <img src="../../assets/images/market/dot_green.png" width="16" heigth="16" alt="" />营业中 </span>
                            <span v-if="scope.row.STATUS==0" style="display:flex;align-items:center;justify-content:center;">
                                <img src="../../assets/images/market/dot_red.png" width="16" heigth="16" alt="" />关闭
                                <label style="visibility:hidden;">中</label>
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="CREATETIME" label="开业时间" width="180">
                        <template slot-scope="scope">
                            <span v-if="scope.row.CREATETIME">{{ scope.row.CREATETIME |filterTimes }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="options" label="操作" width="250">
                        <template slot-scope="scope">
                            <span class="opretions" @click="changeS(scope.row.SHOPID,scope.row.STATUS)">{{ scope.row.STATUS == 1 ? '暂停营业' : '恢复营业'}}</span>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page1" :page-sizes="[6, 8, 10]" :page-size="pageSize1" layout="total, sizes, prev, pager, next, jumper" :total="tableDatas.COUNT"> </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
    export default {
        name: 'store',
        data() {
            return {
                input1: '', //input值
                tableDatas: [], //门店列表				
                selectArr: [], //已选择的数组集合
                activeName: '2', //2-全部 1-营业 0-关闭 这里是字符串类型
                loading: true,
                page1: 1, //当前页数
                pageSize1: 6, //每页多少条				      
            }
        },
        computed: {
            //请求参数
            objs() {
                let obj = {};
                obj.PAGE_NO = this.page1;
                obj.PAGE_SIZE = this.pageSize1;
                this.input1 ? obj.LIKESTR = this.input1 : null;
                let Status = Number(this.activeName);
                if(Status === 1 || Status === 0) {
                    obj.STATUS = Status;
                }
                return obj;
            },            
            //分页数据
            listDatas() {                
                if(this.tableDatas.SHOPARR) {
                    return this.tableDatas.SHOPARR;
                }
            }
        },
        created() {
            this.getList();
        },
        methods: {
        	//门店列表
        	getList(){
        		this.$axiosPost('/4SCAFE/ServShop/getShopList.action', this.objs).then(res => {
                    this.loading = true;
                    if(res.STATUS_CODE === 1) {
                        this.loading = false;
                        this.tableDatas = res;
                    }                    
                })
        	},
            //切换选项卡
            handleClick(tab, event) {
                this.loading = true;
                this.getList();
            },
            handleSelectionChange(val) {
                this.selectArr = val;
                //console.log(this.selectArr);
            },
            handleSizeChange(val) {
            	this.loading = true;
                this.pageSize1 = val;
                this.getList();
            },
            handleCurrentChange(val) {
            	this.loading = true;
                this.page1 = val;
                this.getList();
            },
            //搜索
            search() {
                if(this.input1 == '') {
                    this.$alert('请输入内容', '提示', {
                        confirmButtonText: '确定',
                    });
                    return;
                }
                this.getList();
            },
            //新增门店
            addStore() {
                this.$router.push({
                    path: '/manages/addStore'
                });
            },
            //改变状态
            changeS(id, status) {
                this.$axiosPost('/4SCAFE/ServShop/updateStatusById.action', {
                    SHOP_ID: id,
                    STATUS: status == 1 ? 0 : 1
                }).then(res => {
                    if(res.STATUS_CODE === 1) {
                        for(let i = 0; i < this.listDatas.length; i++) {
                            if(this.listDatas[i].SHOPID == id) {
                                if(this.listDatas[i].STATUS == 1) {
                                    this.$set(this.listDatas[i], 'STATUS', 0);
                                } else {
                                    this.$set(this.listDatas[i], 'STATUS', 1);
                                }
                                this.$message({
                                    type: 'success',
                                    message: '状态已改变'
                                });
                            }
                        }
                    }
                })
            },
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .store {
        header {
            background: #fff;
            font-size: 22px;
            font-weight: 700;
            padding: 20px;
        }
        .contents {
            width: 97%;
            margin: 25px auto;
            padding: 15px 25px;
            background: #fff;
            .ad_list {
                display: flex;
                align-items: center;
                justify-content: space-between;
                .ad_list_title {
                    height: 68px;
                    padding-top: 10px;
                    font-size: 20px;
                }
                .ad_list_tab {
                    display: flex;
                    padding-top: 10px;
                }
            }
            .selected {
                margin-top: 15px;
                border: 1px solid #f0f0f0;
                border-radius: 5px;
                background: #fafafa;
                p {
                    display: flex;
                    align-items: center;
                    img {
                        width: 20px;
                        height: 20px;
                        margin: 0 10px;
                    }
                    span {
                        font-size: 16px;
                        color: #717a7d;
                        label {
                            color: #e7251a;
                        }
                    }
                }
            }
            .tables {
                margin-top: 30px;
                .el-pagination {
                    text-align: center;
                    margin-top: 30px;
                }
                .opretions {
                    color: #1d93ff;
                    cursor: pointer;
                    margin: 0 2px;
                    &:hover {
                        text-decoration: underline;
                    }
                }
            }
        }
    }
</style>